﻿using System;
using System.Xml.Linq;

namespace Patterns.Xml
{
	/// <summary>
	/// Defines a simple bridge between a complex type and a XML object.
	/// </summary>
	/// <typeparam name="T">The object type.</typeparam>
	public class XEntity<T>
	{
		private T _entity;
		private XElement _xml;

		/// <summary>
		/// Initializes a new instance of the <see cref="XEntity{T}"/> class.
		/// </summary>
		/// <param name="entity">The entity.</param>
		public XEntity(T entity)
		{
			Entity = entity;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="XEntity{T}"/> class.
		/// </summary>
		/// <param name="xml">The XML.</param>
		public XEntity(XElement xml)
		{
			Xml = xml;
		}

		/// <summary>
		/// Gets or sets the entity.
		/// </summary>
		/// <value>
		/// The entity.
		/// </value>
		public T Entity
		{
			get { return _entity; }
			set
			{
				_entity = value;
				RefreshXml();
			}
		}

		/// <summary>
		/// Gets or sets the XML.
		/// </summary>
		/// <value>
		/// The XML.
		/// </value>
		public XElement Xml
		{
			get { return _xml; }
			set
			{
				_xml = value;
				RefreshEntity();
			}
		}

		private void RefreshEntity()
		{
			throw new NotImplementedException();
		}

		private void RefreshXml()
		{
			throw new NotImplementedException();
		}
	}
}